Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViSP Python wrapper #1265

Merged
merged 176 commits into from
Dec 14, 2023
Merged

ViSP Python wrapper #1265

merged 176 commits into from
Dec 14, 2023

Conversation

SamFlt
Copy link
Contributor

@SamFlt SamFlt commented Oct 27, 2023

This PR includes an automatic tool to generate Pybind11-based bindings for ViSP. After install, ViSP can now be used from python and most functions should be available.

The PR introduces a new folder, modules/python containing:

  • generator: the Python code to generate pybind11 C++ code, which can then be compiled;
  • bindings: the recipe for building the Pybind code, as well as handcrafted binding functions (e.g. numpy conversions). It may also contain pure python code, that can be added on top of the generated bindings.
  • config: a folder containing the modules (core, io, mbt etc.) configuration;
  • stubs: A way to build "stubs" after compiling the pybind extension and installing the ViSP module. Stubs provide type information and allow for autocompletion in IDE (tested in visual code);
  • docs: Sphinx-based documentation sources for the Python version of ViSP.

A lot more testing is required to ensure that everything works properly.

To build the python bindings:

  • Install pybind11 (on macos: brew install pybind11)
  • Make sure that pip is installed in your Python environment: python -m pip
  • When building ViSP, make sure that BUILD_PYTHON_BINDINGS is on
  • make the target visp_python_bindings
  • To build the documentation, make visp_python_bindings_docs

Known issues can be seen in modules/python/docs/todos.rst

Howto build on macOS

  • Install virtualenv

    % pip3 install virtualenv
    
  • To get access to virtualenv, add its installation directory in your PATH

    % export PATH=$PATH:$HOME/Library/Python/3.9/bin
    
  • Setup virtualenv for visp

    % cd $VISP_WS
    % virtualenv venv
    
  • If you want your virtualenv to also inherit globally installed packages run:

    % virtualenv venv --system-site-packages
    
  • These commands create a venv/ directory in your project where all dependencies are installed. You need to activate it first though (in every terminal instance where you are working on your project):

    % source venv/bin/activate
    (venv) % cd visp-build
    (venv) % cmake ../visp
    (venv) % make -j$(sysctl -n hw.logicalcpu) visp_python_bindings
    
  • Build python documentation

    (venv) % make -j$(sysctl -n hw.logicalcpu) visp_python_bindings_doc
    

    Note that documentation is available in $VISP_WS/visp-build/doc/python/index.html

  • Test python bindings

    (venv) % pip install pytest
    (venv) % python -m pytest visp/modules/python/test
    
  • Launch python mbt example

    (venv) % cd visp/modules/python/examples
    (venv) % pip install opencv-python
    (venv) % export OPENCV_IO_ENABLE_OPENEXR=1
    (venv) % python synthetic_data_mbt.py --data-root ../../../tutorial/tracking/model-based/generic-rgbd-blender
    
  • Launch visual-servoing examples

    (venv) % cd visp/modules/python/examples
    (venv) % python ibvs-four-points.py
    (venv) % python pbvs-four-points.py
    

SamFlt added 30 commits August 16, 2023 14:24
SamFlt added 28 commits December 1, 2023 14:26
@fspindle fspindle merged commit b68f53a into lagadic:master Dec 14, 2023
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants